﻿using Castle.DynamicProxy;
using System.IO;

namespace AopOfAutofacCastleDemo
{
    public class ExceptionHandler : IInterceptor
    {
        private TextWriter _output;

        public ExceptionHandler(TextWriter output)
        {
            _output = output;
        }

        public void Intercept(IInvocation invocation)
        {
            try
            {
                invocation.Proceed();
            }
            catch (System.Exception ex)
            {
                _output.WriteLine($"异常捕获：{ex.Message}.");
            }
        }
    }
}